﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Common;
using Models;

namespace CSMF
{
    public class NormalHomePostCommentModel
    {
        public PageInfo PageInfo { get; set; }
        public int ObjId { get; set; }
        public int ObjTypeId { get; set; }

        public PagedList<CommentInfo> CommentInfos { get; set; }

    }


    public partial class NormalHomePostComment : System.Web.UI.UserControl
    {
        public string SinaRedirectUrl;
        private CommentService _commentService = new CommentService();
        public NormalHomePostCommentModel postCommentModel = null;


        public int CommentObjId
        {
            get { return -1; }
        }


        public int CommentObjType
        {
            get { return (int) ObjType.首页; }
        }



        protected void Page_Load(object sender, EventArgs e)
        {
            var pageSize = int.Parse(ConfigurationManager.AppSettings["CommentPageSize"]);
            postCommentModel = new NormalHomePostCommentModel();
          
            postCommentModel.CommentInfos = _commentService.GetNormalCommentsByObjId( 0,
                                                                               pageSize);

            var pageInfo = new PageInfo()
                               {
                                   PageIndex = postCommentModel.CommentInfos.PageIndex,
                                   PageSize = postCommentModel.CommentInfos.PageSize,
                                   TotalCount = postCommentModel.CommentInfos.TotalCount,
                                   TotalPages = postCommentModel.CommentInfos.TotalPages,
                                   HasPreviousPage = postCommentModel.CommentInfos.HasPreviousPage,
                                   HasNextPage = postCommentModel.CommentInfos.HasNextPage,
                               };

            postCommentModel.PageInfo = pageInfo;
            postCommentModel.ObjId = this.CommentObjId;
            postCommentModel.ObjTypeId = this.CommentObjType;


            var webContext = new WebWorkContext();
            var currentUser = webContext.CurrentUser;

            var sinaService = new SinaService();

            var bound = sinaService.IsCurrentUserBindToWeibo(currentUser.Id);


            showSina.Visible = false;

            //直接用ＳＩＡＮ登录注册
                SinaRedirectUrl = "SinaSmallLogin.aspx";

                showSina.Visible = true;

            //if(!currentUser.IsRegistered())
            //{
            //    //直接用ＳＩＡＮ登录注册
            //    SinaRedirectUrl = "SinaSmallLogin.aspx";

            //    showSina.Visible = true;
            //}
            //else if(currentUser.IsRegistered() &&  !bound)
            //{
            //    //绑定
            //    SinaRedirectUrl = "SinaBind.aspx";
            //    showSina.Visible = true;
            //}
            //else
            //{
            //    SinaRedirectUrl = string.Empty;
            //}

        }
    }
}